package com.polaris.live.im.sfs.processor.impl

import com.polaris.live.common.util.JsonUtils
import com.polaris.live.im.sfs.COMMAND_NOTICE_LUCKY_BAG
import com.polaris.live.im.sfs.bean.pusher.LuckyBagNoticeMessage
import com.polaris.live.im.sfs.bean.pusher.PusherNoticeMessage
import com.polaris.live.im.sfs.core.bean.DataArgument
import com.polaris.live.im.sfs.processor.impl.system.AbstractExcludeMessageProcessor
import org.greenrobot.eventbus.EventBus

/**
 * 福袋消息
 *
 * @author Created by lucas on 2024/6/11 02:50
 * @since 1.0.0
 */
class NoticeLuckyBagMessageProcessor : AbstractExcludeMessageProcessor() {

    override fun shouldProcess(type: Int, command: String): Boolean {
        return command == COMMAND_NOTICE_LUCKY_BAG
    }

    override suspend fun handle(type: Int, command: String, argument: DataArgument) {
        val data = argument.getData<PusherNoticeMessage>() ?: return
        val message = JsonUtils.fromJson<LuckyBagNoticeMessage>(data.content) ?: return

        EventBus.getDefault().post(message)
    }
}